package com.csii.pos.scalegrade;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.csii.adhoc.annotation.OperationLog;
import com.csii.adhoc.controller.BaseController;

import com.csii.pos.scalegrade.service.IBusnScaleGrdDefService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.result.APIResult;
import com.csii.result.PageVo;
import lombok.extern.slf4j.Slf4j;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


 /**
 * @Description: 划分业务规模档次的描述和档次设置
 * @Author: zhanghao
 * @Date:   2021-07-06
 * @Version: V1.0
 */

@RestController
@RequestMapping("/busnScaleGrdDef")
@Slf4j
public class BusnScaleGrdDefController extends BaseController<BusnScaleGrdDef, IBusnScaleGrdDefService>{
	@Autowired
	private IBusnScaleGrdDefService busnScaleGrdDefService;
	 /**
	  * @description: 查询所有的规模名称和对应的唯一id
	  * @Author: zhanghao
	  * @return
	  * @Date: 2021-07-07
	  */
	 @RequestMapping("/findAllScaleNameAndId")
	 public APIResult<?> findAllScaleNameAndId(){
		 List<BusnScaleGrdDef> busnScaleGrdDef = busnScaleGrdDefService.findAllScaleNameAndId();
		 return APIResult.successResult(busnScaleGrdDef);
	 }

	/**
	 * 分页列表查询
	 *
	 * @param busnScaleGrdDef  若输入规模名称则根据规模名称模糊查询对应的记录，否则查询所有记录.
	 * @return
	 * @Date: 2021-07-07
	 */
	@OperationLog(value = "划分业务规模档次的描述和档次设置-分页列表查询")
	@PostMapping(value = "/list")
	public APIResult<?> queryPageList(@RequestBody BusnScaleGrdDef busnScaleGrdDef) {
		Page<BusnScaleGrdDef> page = new Page<>(busnScaleGrdDef.getPageNo(), busnScaleGrdDef.getPageSize());
		IPage<BusnScaleGrdDef> pageList = busnScaleGrdDefService.queryPageList(page, busnScaleGrdDef);
		return  APIResult.successResult(PageVo.getPageVoFromIPage(pageList));
	}

	/**
	 * 规模档次定义表数据添加
	 * @param busnScaleGrdDef
	 * @return "添加成功！"
	 * @Date: 2021-07-07
	 */
	@OperationLog(value = "划分业务规模档次的描述和档次设置-添加")
	@PostMapping(value = "/add")
	public APIResult<?> addBusnScaleGrdDef(@RequestBody BusnScaleGrdDef busnScaleGrdDef) {
		busnScaleGrdDefService.addBusnScaleGrdDef(busnScaleGrdDef);
		return APIResult.successResult("添加成功！");
	}

	/**
	 * 规模档次定义信息编辑
	 *
	 * @param busnScaleGrdDef 更新后的规模档次定义对象，必含id。
	 * @return
	 * @Date: 2021-07-07
	 */
	@OperationLog(value = "划分业务规模档次的描述和档次设置-编辑")
	@PostMapping(value = "/edit")
	public APIResult<?> updateById(@Validated @RequestBody BusnScaleGrdDef busnScaleGrdDef) {
		UpdateWrapper updateWrapper = new UpdateWrapper();
		updateWrapper.eq("SCALE_GRD_NO",busnScaleGrdDef.getScaleGrdNo());
		busnScaleGrdDefService.update(busnScaleGrdDef,updateWrapper);
		return APIResult.successResult("编辑成功!");
	}

	 /**
	  * @description:  输入框查询是提示接口
	  * @param: hintVo
	  * @return:  模糊查询list
	  * @author liuzhonghua
	  * @date:
	  */
	 @RequestMapping("queryHint")
	 public APIResult<?> queryHint(@RequestBody BusnScaleGrdDef busnScaleGrdDef) {
		 QueryWrapper<BusnScaleGrdDef> queryWrapper = new QueryWrapper<>();
		 queryWrapper.select("DISTINCT SCALE_GRD_NM").like("SCALE_GRD_NM",busnScaleGrdDef.getScaleGrdNm());
		 List<BusnScaleGrdDef> list = busnScaleGrdDefService.list(queryWrapper);
		 return APIResult.successResult(list);
	 }

//	/**
//	 *   通过id删除
//	 * @param busnScaleGrdDef 要删除的对象，必含id。
//	 * @return
//	 */
//	@OperationLog(value = "划分业务规模档次的描述和档次设置-通过id删除")
//	@PostMapping(value = "/delete")
//	public APIResult<?> delete(@RequestBody BusnScaleGrdDef busnScaleGrdDef) {
//		busnScaleGrdDefService.removeById(busnScaleGrdDef.getScaleGrdNo());
//		return APIResult.successResult("删除成功!");
//	}

	/**
	  *  批量删除
	  *
	  * @param ids
	  * @return
	  */
	@OperationLog(value = "划分业务规模档次的描述和档次设置-批量删除")
	@PostMapping(value = "/deleteBatch")
	public APIResult<?> deleteBatch(@Validated @RequestBody List<BusnScaleGrdDef> ids) {
		this.busnScaleGrdDefService.removeByIds(ids.stream().map(BusnScaleGrdDef::getScaleGrdNo).collect(Collectors.toList()));
		return APIResult.successResult("批量删除成功!");
	}


//
//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param busnScaleGrdDefVO
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletResponse response, BusnScaleGrdDefVO busnScaleGrdDefVO) {
//        BusnScaleGrdDef busnScaleGrdDef  = ConvertUtils.convert(BusnScaleGrdDef.class,busnScaleGrdDefVO);
//        return super.exportXls( busnScaleGrdDef, BusnScaleGrdDef.class, "划分业务规模档次的描述和档次设置");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public APIResult<?> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
//        return APIResult.successResult(super.importExcel(file, BusnScaleGrdDef.class));
//    }
}
